package top.minuy.algorithm.search.string;

import top.minuy.util.constant.SubstringMatchType;
import top.minuy.util.helper.FileHelper;
import top.minuy.util.helper.SubstringMatchHelper;

/**
 * @author Minuy
 * @time 15:41
 * @date 2021/11/12
 */
public class Test {
    public static void main(String[] args) {
        String content = FileHelper.readFile("src/top/minuy/res/Pride_and_Prejudice.txt");

        String t1 = "china";
        System.out.println("target : "+t1);
        SubstringMatchHelper.matchTest(SubstringMatchType.bruteForce,content,t1);
        SubstringMatchHelper.matchTest(SubstringMatchType.rabinKarp,content,t1);
        SubstringMatchHelper.matchTest(SubstringMatchType.kmp,content,t1);

        String t2 = "zxy";
        System.out.println("target : "+t2);
        SubstringMatchHelper.matchTest(SubstringMatchType.bruteForce,content,t2);
        SubstringMatchHelper.matchTest(SubstringMatchType.rabinKarp,content,t2);
        SubstringMatchHelper.matchTest(SubstringMatchType.kmp,content,t2);

        // 最坏的情况
        System.out.println("最坏情况 : ");
        int s = 1000000,t = 10000;
        StringBuilder sbs = new StringBuilder();
        StringBuilder sbt = new StringBuilder();
        for (int i=0;i<s;i++){
            sbs.append('a');
        }
        for (int i=0;i<t-1;i++){
            sbt.append('a');
        }
        sbt.append('b');

        String tw = sbt.toString();
        // System.out.println("target : "+tw);
        SubstringMatchHelper.matchTest(SubstringMatchType.bruteForce,sbs.toString(),tw);
        SubstringMatchHelper.matchTest(SubstringMatchType.rabinKarp,sbs.toString(),tw);
        SubstringMatchHelper.matchTest(SubstringMatchType.kmp,sbs.toString(),tw);

    }


}
